package org.garbagecan.quartzstudy.cron;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.quartz.CronExpression;
import org.quartz.impl.calendar.CronCalendar;

public class TestCronCalendar {
	public static void test() throws Exception {
		print("\nTestCronCalendar.test: -------------------------------");

		String s = "0 0 10 ? * * 2008";
		CronExpression ce = new CronExpression(s);
		CronCalendar cc = new CronCalendar(s);
		print("The cron expressions list is :" + s);

		String sDate;
		sDate = "2008-02-14 10:00:00.000";
		Date date = parseToDate(sDate);

		print(sDate + " isSatisfiedBy :  " + ce.isSatisfiedBy(date));
		print(sDate + "isTimeIncluded : " + cc.isTimeIncluded(date.getTime()));
		print(sDate + "next Include Time : "
				+ new Date(cc.getNextIncludedTime(date.getTime())));
	}

	public static Date parseToDate(String s) throws ParseException {
		DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
		Date date = df.parse(s);
		return date;
	}

	public static void print(Object obj) {
		System.out.print("\t");
		System.out.println(obj);
	}
}
